package Viewer;

import java.io.File;
import java.util.ArrayList;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import Parser.CheckReference;

/**
 * The referenceChooser opens and OptionPane to select the reference information
 * and the range for visualisation
 * 
 * @author stlo
 * 
 */
public class ReferenceChooser {

	private String reference;
	private String range;
	private boolean loadable;

	/**
	 * Constructor of the ReferenceChooser
	 * @param file File to select reference and range from
	 */
	public ReferenceChooser(File file) {

		ArrayList<String> ref = new CheckReference(file).getList();
		JComboBox box1 = new JComboBox(ref.toArray());
		JRadioButton all = new JRadioButton("Complete");
		JTextField position = new JTextField("0:10000");

		Object[] message = { "Choose reference:\n", box1, new JLabel(), "Select region:", all, position };

		this.reference = "";
		this.range = "";
		this.loadable= false;
		int resp = JOptionPane.showConfirmDialog(null, message, "Select", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
		if (resp == JOptionPane.OK_OPTION) {
			reference = box1.getItemAt(box1.getSelectedIndex()).toString();
			range = "";
			if (all.isSelected())
				range = "complete";
			else
				range = position.getText();

			this.loadable = true;
		}
	}

	/**
	 * Returns the name of the selected reference
	 * @return the selected reference
	 */
	public String getReference() {
		return reference;
	}
	/**
	 * Returns the range 
	 * @return either "complete" or two ints separated by "-" or ":"
	 */
	public String getRange() {
		return range;
	}

	public boolean isLoadable() {
		return this.loadable;
	}
}
